package org.jeecg.modules.xl.shengfutong.request;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.jeecg.modules.xl.shengfutong.config.ShengftConf;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @version 创建时间：2020年10月15日 下午4:06:00
 * @Description 支付请求
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class PayRequest extends BaseRequest{
	private String subMchId;
	
	private String tradeType;
	
	private String sdpAppId;
	
	private String mchMemberInfo;
	
	private String isNeedShare = "false";
	
	private String attach;
	
	private String extra;
	
	private String outTradeNo;
	
	private String timeExpire;
	
	private String notifyUrl;

	private int totalFee = 0;
	
	private String body;
	
	private String detail;
	
	private String currency = "CNY";
	
	private String pageUrl ;
	
	private String clientIp;
	
	private String authCode;
	
	private String nonceStr;
	private String signType;
	
	private String sign;
	
	
	/**支付请求类初始化
	 * @param outTradeNo
	 * @param attach
	 * @param clientIp
	 * @return
	 */
	public static PayRequest buildBasePayRequest(String outTradeNo,String attach,int totalFee,String clientIp,String tradeType){
		PayRequest request = new PayRequest();
		request.setBody("");
		request.setAttach(attach);
		request.setClientIp(clientIp);
		request.setCurrency(ShengftConf.CNY);
		request.setDetail("");
		//可以动态传入
		request.setBody("聚合支付");
		//默认订单不分账
		request.setIsNeedShare("false");
		
		request.setMchId(ShengftConf.MCH_ID);
		request.setNotifyUrl(ShengftConf.NOTIFYURL);
		request.setOutTradeNo(outTradeNo);
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		//过期时间=当前时间+1天
		Date timeExpire = new Date(System.currentTimeMillis()+24*60*60*1000);
		request.setTimeExpire(sdf.format(timeExpire));
		
		//金额单位为分
		request.setTotalFee(totalFee);
		request.setTradeType(tradeType);
		return request;
	}

	
	
}
